﻿using UnityEngine;

namespace Core
{
    public class FileSystem : Component, IAwake, IFileData
    {
        private IFileData file;

        public void Awake()
        {
            switch (Application.platform)
            {
                case RuntimePlatform.WindowsEditor:
                case RuntimePlatform.Android:
                case RuntimePlatform.IPhonePlayer:
                    file = G.Factory.Create<NativeFileData>();
                    break;
                case RuntimePlatform.WebGLPlayer:
                    file = G.Factory.Create<WXWASMFileData>();
                    break;
                default:
                    log.err($"目前尚不支持的平台 {Application.platform}");
                    break;
            }
        }

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();
        }

        public string Read(string path)
        {
            return file.Read(path);
        }

        public void Append(string path, string content)
        {
            file.Append(path, content);
        }

        public void Write(string path, string content)
        {
            file.Write(path, content);
        }

        public void Delete(string path)
        {
            file.Delete(path);
        }
    }
}
